package com.chukun.flink.dataset.operator;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.java.DataSet;
import org.apache.flink.api.java.ExecutionEnvironment;
import org.apache.flink.api.java.operators.DataSource;
import org.apache.flink.api.java.tuple.Tuple2;

/**
 * @author chukun
 * @version 1.0.0
 * @description map 操作符的基本操作
 * @createTime 2022年05月28日 20:35:00
 */
public class MapOperator {

    public static void main(String[] args) throws Exception {

        ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

        DataSource<Long> dataSource = env.generateSequence(1, 5);

        DataSet<Tuple2<Long, Integer>> mappedData = dataSource.map(new MapFunction<Long, Tuple2<Long, Integer>>() {
            @Override
            public Tuple2<Long, Integer> map(Long value) throws Exception {
                return Tuple2.of(value * 100, value.hashCode());
            }
        });

        mappedData.print("MapFunction");

        env.execute("MapOperator");
    }
}
